package com.example.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordCountReduce extends
             // K3        V3       K4    V4
        Reducer<Text, IntWritable,Text,IntWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        //遍历reduce的v3，求和
        for (IntWritable value : values) {
            int count = value.get();
            sum+=count;
        }
        IntWritable v4 = new IntWritable();
        v4.set(sum);
        //reduce输出
        context.write(key, v4);

    }
}
